home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap2 / 2_7 / testhost.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-15  |  824 b   |  42 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. main()
  5. {
  6.     char* remote_host;
  7.  
  8.     printf("Content-type: text/html\n\n");
  9.  
  10.     printf("<HTML>\n");
  11.     printf("<HEAD><TITLE>CGI Script How-to: Test Script</TITLE></HEAD>\n");
  12.     printf("<BODY>\n");
  13.  
  14.     printf("<H1>CGI Script How-to<BR>determine the client machine's name</H1>\n");
  15.  
  16.     remote_host = getenv("REMOTE_HOST");
  17.  
  18.     /* Check the value */
  19.  
  20.     if  (remote_host == NULL)
  21.     {
  22.         /* REMOTE_HOST is undefined so let's try REMOTE_ADDR */
  23.         remote_host = getenv("REMOTE_ADDR");
  24.         if (remote_host == NULL)
  25.         {
  26.             /* REMOTE_ADDR is also undefined so we give up */
  27.             remote_host = "somewhere on the Internet";
  28.         }
  29.     }    
  30.  
  31.     /* print the remote host (or address) and exit */
  32.  
  33.     printf("Hello, you are a user from <B>%s</B>\n", remote_host);
  34.  
  35.     printf("</BODY></HTML>\n");
  36.     exit(0);
  37. }
  38.  
  39. /*
  40.  * end of testhost.c
  41.  */
  42.